package com.zzf.concurrent.example.daemon;

import com.zzf.concurrent.example.util.TimeUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author GaoFeng2017
 * @date 2019/8/5 10:28
 */
@Slf4j
public class DaemonThreadExample3 {
    public static void main(String[] args) {

        // 如果外部线程也是守护线程，那么内部线程在创建时，如果未指定，默认为守护线程
        Thread t1 = new Thread(() -> {
            Thread innerThread = new Thread(() -> {
                while (true) {
                   TimeUtil.sleep(500);
                    log.info("发送心跳包, {}", Thread.currentThread().isDaemon());
                }
            });

            // innerThread.setDaemon(false);
            innerThread.start();
            TimeUtil.sleep(2000);
            log.info("聊天室关闭");
        });

        t1.setDaemon(true);
        t1.start();

        TimeUtil.sleep(1000);
        log.info("系统已关闭");
    }
}
